package com.wangshuo.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wangshuo.config.Result;
import com.wangshuo.entity.Goods;
import com.wangshuo.entity.Orderr;
import com.wangshuo.service.GoodsService;
import com.wangshuo.service.OrderrService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/chart")
public class ChartController {
    @Resource
    private GoodsService goodsService;
    @Resource
    private OrderrService orderrService;
    @PostMapping("/xstj")
    public Result xstj(){
        List<Goods> list=goodsService.list();
        HashMap<String,Object> map=new HashMap<>();
       List<Object> list1=new ArrayList<>();
        List<Object> list2=new ArrayList<>();

        for (Goods goods:list){
            list1.add(goods.getName());
            LambdaQueryWrapper<Orderr> lambdaQueryWrapper=new LambdaQueryWrapper<>();
            lambdaQueryWrapper.eq(Orderr::getGoodid,goods.getId());
         Long  count=  orderrService.count(lambdaQueryWrapper);
         list2.add(count);
        }
        map.put("xdata",list1);
        map.put("ydata",list2);
        return Result.ok(map);

    }

}
